<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>注册</title>
		<link href="css/user.css" rel="stylesheet" />
		<script src="js/vue.js"></script>
		<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
		<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

	</head>
	<body>
		<div id="out">
			<div id="title">注册</div>
			<div>
				<input type="text" name="phone" placeholder="请输入手机号码" id="phone" v-model="userPhone" />
			</div>
			<div>
				<input type="password" name="password" placeholder="请输入密码" id="password" v-model="userPassword" />
			</div>
			<div>
				<input type="text" name="name" placeholder="请输入真实姓名" id="name" v-model="userName" />
			</div>
			<div>
				<input type="button" value="注册" id="button" v-on:click="register" />
			</div>
		</div>
	</body>
	<script>
		// http://localhost:8080/kaoqin/register.html
		window.onload = function() {
			var vue = new Vue({
				el: '#out',
				data: {
					userPhone: '',
					userPassword: '',
					userName:''
				},
				methods: {
					register: function() {

						var url = 'http://localhost:8080/kaoqin/user/register';
						// url=发送请求的链接，和后端匹配
						// 第二个参数规定是对象：{元素名:元素}    要传给后台的数据
						// emulateJSON:false固定     是false还是true视实际情况更改
						this.$http.post(url, {
							phone: this.userPhone,
							password: this.userPassword,
							name: this.userName
						}, {
							emulateJSON: false
						}).then(function(backdatas) {
							console.log(backdatas);


							var code = backdatas.body.code;
							console.log(code);
							

							// 拿到后台返回的数据
							var data=backdatas.body.data;
							console.log(data);
							
							
							var message = backdatas.body.message;
							console.log(message);

							var message1 = backdatas.body.message1;
							console.log(message1);



							if (code == 691) {
								alert(message + '\n' + message1);
								location.reload();
							} else if (code == 200) {
								alert(message);
								window.location.href =
									"http://localhost:8080/kaoqin/login.html"
							}
						});
					}
				}
			});
		};
	</script>
</html>
